package com.example.vueserver.vueserver.utils;

import com.example.vueserver.vueserver.bean.SysMenu;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SysMenusUtils {
    public static List<SysMenu> getTreeMenu(List<SysMenu> menus) {
        List<SysMenu> treeMenus = new ArrayList<>();
        for (SysMenu menu : menus) {
            if (null != menu) {
                if (null == menu.getParentid() || "".equals(menu.getParentid())) {
                    treeMenus.add(menu);
                }
                for (SysMenu s_menu : menus) {
                    if(null!=s_menu){
                        if (null!=s_menu.getParentid()&&s_menu.getParentid().equals(menu.getId())) {
                            if (menu.getSubs() == null) {
                                menu.setSubs(new ArrayList<SysMenu>());
                            }
                            menu.getSubs().add(s_menu);
                        }
                    }
                }
            }
        }
        return treeMenus;
    }
}
